package com.hnevc.servicedemo;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

public class MainActivity extends AppCompatActivity {
    MYServiceConnection connection = new MYServiceConnection();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    public void buttononClick(View viwe){
        int id =viwe.getId();
        switch (id){
            case R.id.id_btn_start_service:
                Intent intent = new Intent();
                intent.setClass(this,MYService.class);
                startService(intent);
                break;
            case  R.id.id_btn_stop_service:
                Intent intent1=new Intent();
                intent1.setClass(this,MYService.class);
                stopService(intent1);

                break;
            case R.id.id_btn_bind_service:
                Intent intent2 =new Intent();
                intent2.setClass(this,MYService.class);
                bindService(intent2,connection,BIND_AUTO_CREATE);
                break;
            case R.id.id_btn_onunbind_service:
                unbindService(connection);
            case  R.id.id_btn__play;
                binder.play();
                break;
        }

    }
    class MYServiceConnection implements  ServiceConnection{

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {

        }
          MYService.MyBinder binder=(MYService.MyBinder) service;
        @Override
        public void onServiceDisconnected(ComponentName name) {

        }
    }
}
